<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<meta name="renderer" content="webkit">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<meta name="viewport"
			content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
		<link rel="stylesheet" href="../../../layuiadmin/layui/css/layui.css" media="all">
		<link rel="stylesheet" href="../../../layuiadmin/style/admin.css" media="all">
		<link rel="stylesheet" href="../../../css/common.css" media="all">
		<style>
			.service_goods {
				display: none;
			}

			.choose_shopname {
				line-height: 46px;
			}
		</style>
	</head>
	<body>

		<div class="layui-fluid">
			<div class="layui-row" id="view">
				<form class="layui-form" wid100 lay-filter="test_detail">
					<div class="layui-card">
                        <div class="layui-card-body">
                            <table class="layui-hide" id="ID-table-demo-data"></table>
                        </div>
					</div>

					<div class="layui-form-item layui-layout-admin">
						<div class="layui-input-block">
							<div class="layui-footer" style="left: 0;">
								<!-- <button type="reset" class="layui-btn layui-btn-primary">重置</button> -->
                                <button class="layui-btn" lay-submit="" lay-filter="demo1">确认导入</button>
                                <button class="layui-btn" lay-submit="" lay-filter="demo2">取消</button>
							</div>
						</div>
					</div>
				</form>
			</div>
		</div>
		
		<script src="../../../layuiadmin/layui/layui.js"></script>
		<script src="../../../js/jquery.min.js"></script>
		<script src="../../../js/jquery.jqprint-0.3.js"></script>
		<script src="../../../js/ace/ace.js"></script>
		<script src="../../../js/common.js"></script>
		<!--<script src="https://raw.githack.com/hnzzmsf/layui-formSelects/master/dist/formSelects-v4.min.js" type="text/javascript" charset="utf-8"></script>-->
		<script src="../../../layuiadmin/modules/formSelects-v4.js"></script>
		<script>
            layui.config({
			base: '../../../layuiadmin/' //静态资源所在路径
			}).extend({
			tinymce: '../tinymce/tinymce',
			index: 'lib/index' //主入口模块
			}).use(['index', 'form', 'laytpl', 'laydate', 'layedit', 'upload', 'tinymce', 'util', 'table'], function() {
			var $ = layui.$,
				admin = layui.admin,
				upload = layui.upload,
				laytpl = layui.laytpl,
				laydate = layui.laydate,
				util = layui.util,
				tinymce = layui.tinymce,
				form = layui.form;
                table = layui.table;
                var datalist=JSON.parse(sessionStorage.getItem("datalist"))
                console.log(JSON.parse(sessionStorage.getItem("datalist")),"======sessionStorage11====")
              // 已知数据渲染
                var inst = table.render({
                    elem: '#ID-table-demo-data',
                    cols: [[ //标题栏
                    // {field: 'id', title: 'ID', width: 80, sort: true},
                    {field: 'catname', title: '分类', width: 120},
                    // {field: 'status', title: '产品状态', minWidth: 160},
                    // {field: 'type', title: '商品类型', width: 80},
                    // {field: 'client', title: '客户端类型', width: 100},
                    // {field: 'spuname', title: '产品名称', width: 80, sort: true},
                    {field: 'skuname', title: '商品名称', width: 120, sort: true},
                    // {field: 'fq', title: '分期', width: 80, sort: true},
                    // {field: 'channelid_name', title: '频道名称', width: 80, sort: true},
                    // {field: 'sub_shopname', title: '店铺名称', width: 80, sort: true},
                    {field: 'is_recommend', title: '是否推荐', width: 120, sort: true},
                    // {field: 'cart', title: '能否加入购物车', width: 80, sort: true},
                    {field: 'title', title: '商品简称', width: 120, sort: true},
                    // {field: 'low_quantity', title: '最低购买数量', width: 80, sort: true},
                    // {field: 'hits', title: '点击量', width: 80, sort: true},
                    // {field: 'categoryname', title: '分类名称', width: 80, sort: true},
                    // {field: 'catid', title: '分类', width: 80, sort: true},
                    {field: 'measure_unit', title: '计量单位', width: 120, sort: true},
                    {field: 'cost_price', title: '成本价', width: 120, sort: true},
                    {field: 'price', title: '原价', width: 80, sort: true},
                    {field: 'price_member', title: '会员价', width: 120, sort: true},
                    // {field: 'discount', title: '折扣', width: 80, sort: true},
                    // {field: 'give_score', title: '赠送积分', width: 80, sort: true},
                    {field: 'stock', title: '库存', width: 80, sort: true},
                    {field: 'price_waybill', title: '商品运费', width: 120, sort: true},
                    {field: 'specname', title: '规格名称', width: 120, sort: true},
                    {field: 'specparam', title: '规格参数', width: 120, sort: true},
                    // {field: 'sales', title: '当前销量', width: 80, sort: true},
                    {field: 'intro', title: '商品简介', width: 120, sort: true},
                    // {field: 'zhutu', title: '商品主图', width: 80, sort: true},
                    // {field: 'lunbo', title: '商品轮播图', width: 80, sort: true},
                    ]],
                    data: datalist,
                    //skin: 'line', // 表格风格
                    //even: true,
                    // page: true, // 是否显示分页
                    // limits: [5, 10, 15],
                    // limit: 5 // 每页默认显示的数量
                });
              //监听提交
			form.on('submit(demo1)', function() {
                var lock = false
                console.log(datalist,"================datalist")
                    layer.confirm('确定要提交数据？', function() {
                        if (!lock) {
                            lock = true
                            // loading();
                            for (let i = 0; i < datalist.length; i++) {
                                datalist[i].sub_shopid=10000
                                if (datalist[i].id) {
                                    submitdata(server.updategoods,datalist[i]);
                                    // console.log(_data.examples_img_url);
                                } else {
                                    setTimeout(function(){
                                        submitdata(server.addgoods,datalist[i],i);
                                    }, i*300);
                                    // console.log(_data, '0000')
                                }
                            }
                        }
                    }, function() {
                        layer.msg('取消操作');
                    });
                    return false;
                });
                function submitdata(_url,data,i) {
                    delete data.LAY_TABLE_INDEX;
                    data.status=1;
                    data.type=0;
                    data.client="202,201,200";
                    data.fq=0;
                    data.is_recommend=1;
                    data.cart=1;
                    data.low_quantity=1;
                    data.hits=0;
					$.post(_url,data, function(res, status) {
						if (status == 'success') {
							if (res.code == 0) {
                                console.log(i,data,"==========datalist.length")
                                if(i == datalist.length-1){
                                    layer.alert('操作成功', function() {
                                        parent.layer.closeAll();
                                        parent.layui.table.reload('test-table-operate');
                                    });
                                }
							} else {
								closeloading();
								layer.msg(res.msg);
							}
						} else {
							layer.msg('服务器连接错误');
						}
					});
                }
                //取消
                form.on('submit(demo2)', function() {
                    parent.layer.closeAll();
                    parent.layui.table.reload('test-table-operate');
                })
                
            });
            </script>
	</body>
</html>